package com.xiaoniu.forum.web.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.xiaoniu.forum.common.utils.CommonQueryVo;

import com.xiaoniu.forum.entity.CommunityTopicStatusEntity;
import com.xiaoniu.forum.entity.vo.ComunityTopiclUpdateInfoVo;
import com.xiaoniu.forum.entity.vo.PassListVo;
import com.xiaoniu.forum.form.TopicSaveOrUpdateForm;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.xiaoniu.forum.service.CommunityTopicService;
import com.xiaoniu.forum.common.utils.PageUtils;
import com.xiaoniu.forum.common.utils.R;



/**
 * 话题表
 *
 * @author xiaoniu
 * @email 55333@qq.com
 * @date 2021-03-23 15:07:41
 */
@RestController
@RequestMapping("forum/communitytopic")
public class CommunityTopicController {
    @Autowired
    private CommunityTopicService communityTopicService;


    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("forum:communitytopic:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = communityTopicService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("forum:communitytopic:info")
    public R info(@PathVariable("id") String id){
		ComunityTopiclUpdateInfoVo comunityTopiclUpdateInfoVo = communityTopicService.getById(id);

        return R.ok().put("communityTopic", comunityTopiclUpdateInfoVo);
    }


    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("forum:communitytopic:save")
    public R save(@RequestBody TopicSaveOrUpdateForm form){
		communityTopicService.save(form);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("forum:communitytopic:update")
    public R update(@RequestBody TopicSaveOrUpdateForm form){
		communityTopicService.updateById(form);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("forum:communitytopic:delete")
    public R delete(@RequestBody String[] ids){
		communityTopicService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    /**
     * 多条件查询列表
     */
    @PostMapping("/multiConditList")
    @ApiOperation("多条件查询列表")
    public R multiConditList(@RequestBody CommonQueryVo queryVo){
        PageUtils page = communityTopicService.queryPage(queryVo);
        return R.ok().put("page",page);
    }

    @GetMapping("/statusInfo/{communityTopicId}")
    public R getTopicStatusBycommunityTopicId(@PathVariable String communityTopicId){
        CommunityTopicStatusEntity communityTopicStatusEntity = communityTopicService.getTopicStatusBycommunityTopicId(communityTopicId);
        return R.ok().put("data",communityTopicStatusEntity);
    }

    @PostMapping("/statusUpdate")
    public R updateTopicStatus(@RequestBody CommunityTopicStatusEntity communityTopicStatusEntity){
        communityTopicService.updateTopicStatus(communityTopicStatusEntity);
        return R.ok();
    }

    /**
     * 查询分页列表 审核列表封装格式
     * @param params 分页参数
     * @return 返回List集合
     */
    @GetMapping("/getListForPass")
    public R getListForPass(@RequestParam Map<String, Object> params){
        PageUtils page = communityTopicService.getListForPass(params);
        return R.ok().put("page",page);
    }

    /**
     * 审核通过
     * @param communityTopicId
     * @return
     */
    @PostMapping("/passed/{communityTopicId}")
    public R passed(@PathVariable String communityTopicId){
        communityTopicService.passed(communityTopicId);
        return R.ok();
    }

    /**
     * 审核不通过
     */
    @PostMapping("/passedFailed/{communityTopicCommentId}")
    public R passedFailed(@PathVariable String communityTopicCommentId,@RequestBody String message){
        communityTopicService.passedFailed(communityTopicCommentId,message);
        return R.ok();
    }

    /**
     * 根据id返回话题内容 标题+内容 拼接
     */
    @PostMapping("/content/{id}")
    public R getContentById(@PathVariable String id){
        String content = communityTopicService.getContentById(id);
        return R.ok().put("content",content);
    }
}
